import { defineStore } from "pinia"
import { ref } from "vue"
import games_nav from "./nav/games"
import modules_nav from "./nav/modules"
import works_nav from "./nav/works"

export const useNavStore = defineStore(
	"nav",
	() => {
		// 0:案例 1:组件 2:游戏
		const menu_obj = ref({
			0: [
				{
					title: "案例",
					id: 1,
					list: works_nav
				},
			],
			1: [
				{
					title: "组件",
					id: 1,
					list: modules_nav,
				},
			],
			2: [
				{
					title: "游戏",
					id: 1,
					list: games_nav
				},
			],
		})

		const nav_select_menu = ref({
			0: "1-1",
			1: "1-1",
			2: "1-1",
		})

		const setNavSelectMenu = (val) => {
			nav_select_menu.value = {
				...nav_select_menu.value,
				...val,
			}
		}

		return {
			menu_obj,
			nav_select_menu,
			setNavSelectMenu,
		}
	},
	{
		persist: {
			enabled: true,
			strategies: {
				user: {
					storage: localStorage,
					paths: ["menu_obj", "nav_select_menu"],
				},
			},
		},
	}
)